<!-- 要闻的组件 -->
<template>
	<scroll-view scroll-y="true" class="important-news" refresher-enabled @scrolltolower='loadMore' :refresher-triggered="triggered"
	 @refresherrefresh='refreshData'>
		<view>
			<view class="news-item" v-for="item in newsList" :key="item.cmsId">
				{{item.title}}
			</view>
		</view>
	</scroll-view>
</template>

<script>
	import {
		get_label
	} from '@/common/api/modules/home.js'
	export default {
		data() {
			return {
				loadKey: true,
				triggered: false,
				newsList: [],
				pageSize: 10
			}
		},
		created() {
			this.get_label()
		},
		methods: {
			get_label(page) {
				if (!this.loadKey) return
				this.loadKey = false
				get_label({
					page: page||(Math.floor(this.newsList.length / this.pageSize) + 1),
					limit: this.pageSize
				}).then(res => {
					if(page===1){
						this.newsList=[]
					}
					this.newsList = [...this.newsList, ...res.data]
				}).finally(() => {
					this.loadKey = true
					this.triggered=false
				})
			},
			loadMore() {
				this.get_label()
			},
			refreshData() {
				this.triggered=true
				this.get_label(1)
			}
		},
	}
</script>

<style lang="scss">
	.important-news {
		height: 100%;

		.news-item {
			height: 100px;
		}
	}
</style>
